<?php

namespace app\admin\model;

use think\Db;
use app\admin\model\Common;
use think\Session;
use think\Validate;

class  Extrain extends Common
{
	//培训经历添加
	public function WriteExtrain($param)
	{
		$info['train_id']=$param['train_id'];
		$info['traindata_name']=$param['traindata_name'];
		$info['company']=$param['company'];
		$info['traindata_address']=$param['traindata_address'];
		$info['start_time']=$param['start_time'];
		$info['end_time']=$param['end_time'];
		$info['traindata_level']=$param['traindata_level'];
		$info['status']=2;
    $info['status1']=2;
    $info['name']=$param['name'];
		$res=Db::table('oa_admin_extrain')
                   ->insert($info);
       if($res){
            return true;
       }else{
       	return false;
       }
		
	}

  //培训经历列表
  public function ListExtrain($param)
  {

    // 自己填写的
    $list = Db::table('oa_admin_extrain')
        ->where('train_id',$param['train_id'])
        ->field('traindata_name,start_time,end_time,company,traindata_address,traindata_level,status')
        ->select();
    // 申报的
    $data = Db::table('oa_admin_checkno')
          ->alias('c')
          ->join('oa_admin_traindata t', 'c.traindata_id = t.id')
          ->where('c.train_id', $param['train_id'])
          ->where('c.status', 2)
          ->where('c.status1', 2)
          ->where('t.status', 2)
          ->field('t.traindata_name, t.start_time, t.end_time, t.company, t.traindata_address, t.level as traindata_level, t.status')
          ->select();
    foreach ($data as $key => $value) {
      array_push($list, $value);
    }
     return $list;
  }
    //培训经历修改
     public function ReviseExtrain($param)
  {
    $id=$param['id'];
    $info['traindata_name']=$param['traindata_name'];
    $info['start_time']=$param['start_time'];
    $info['end_time']=$param['end_time'];
    $info['company']=$param['company'];
    $info['traindata_address']=$param['traindata_address'];
    $info['traindata_level']=$param['traindata_level'];
    $info['updata_time']=date('Y-m-d');
    $status=Db::table('oa_admin_extrain')
            ->where('id',$id)
            ->field('status')
            ->select();
         if($status[0]['status']=='2')
          {
            $info['status']=4; 
            $info['ps']='培训经历';
          }if($status[0]['status']=='3'){
          	$info['status']=1; 
          }if($status[0]['status']=='1'){
          	$info['status']=1;
          }

         $res= Db::table('oa_admin_extrain')
          ->where('id',$id)
          ->find();
     if($res){
         Db::table('oa_admin_extrain')
          ->where('id',$id)
          ->update([
            'traindata_name'=> $info['traindata_name'],
            'start_time'=>$info['start_time'],
            'end_time'=>$info['end_time'],
            'company'=>$info['company'],
            'traindata_address'=>$info['traindata_address'],
            'traindata_level'=>$info['traindata_level'],
            'status'=> $info['status'],
            'updata_time'=>$info['updata_time'],
            'ps'=>$info['ps'],
          ]);

           return true;
          }else{
          	return false;
          }
  }
    //培训经历删除
    public function DeleteExtrain($param)
    {
    	$id=$param['id'];
    	$res= Db::table('oa_admin_extrain')
          ->where('id',$id)
          ->delete();
          if($res){
          	return true;
          }else{
          	return false;
          }
    }
}
